// const axios = require('axios');
// const { net } = require('electron');
import { net } from 'electron';

export function postRequest(url: string, dataParams?: any): Promise<any> {
  return new Promise((resolve, reject) => {
    const request = net.request({
      url,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
      },
    });
    request.write(JSON.stringify(dataParams || {}));
    request.on('response', (response) => {
      console.log(`STATUS: ${response.statusCode}`);
      response.on('data', (chunk) => {
        resolve(chunk.toString());
      });
      response.on('end', () => {
        console.log('No more data in response.');
      });
      response.on('error', reject);
    });
    request.end();
  });
}

// function postRequest(url, dataParams) {
//   return axios({
//     url,
//     method: 'POST',
//     data: dataParams,
//   }).then((response) => {
//     return response.data;
//   });
// }
